//package com.nifty.base.mq.util;
//
//
//import com.google.common.util.concurrent.ThreadFactoryBuilder;
//import com.nifty.base.message.controller.WebSocketServerEndpoint;
//import com.nifty.base.util.JsonUtils;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.amqp.rabbit.support.CorrelationData;
//import org.springframework.stereotype.Component;
//
//import java.util.Collection;
//import java.util.concurrent.*;
//
//@Component
//public class RabbitPushUtil implements RabbitTemplate.ConfirmCallback {
//
//    public static final String NOTIFY_CHANNEL = "notify";
//
//    public void SendMsg(String message) {
//        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
//                .setNameFormat("sendMsg-thread").build();
//
//        //Common Thread Pool
//        ExecutorService pool = new ThreadPoolExecutor(5, 200,
//                60L, TimeUnit.MILLISECONDS,
//                new LinkedBlockingQueue<Runnable>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
//        pool.execute(new SendMsg(message));
//        pool.shutdown();
//    }
//
//    private static Long getUserIdFromJsonStr(String jsonStr) {
//        return Long.valueOf(jsonStr.split("-")[0]);
//    }
//
//    private static String genNoticeJsonStr(Long userId, Object msg) {
//        String json = JsonUtils.toJson(msg);
//        return userId + "-" + json;
//    }
//
//    public static void pushJsonMessage(Long userId, Object msg) {
//
//    }
//
//    public static void pushJsonMessage(Collection<Long> userIds, Object msg) {
//        for (Long userId : userIds) {
//            pushJsonMessage(userId, msg);
//        }
//    }
//
//    /**
//     * 回调
//     * @param correlationData
//     * @param ack
//     * @param cause
//     */
//    @Override
//    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
//        System.out.println(" 回调id:" + correlationData);
//        if (ack) {
//            System.out.println("消息成功消费");
//        } else {
//            System.out.println("消息消费失败:" + cause);
//        }
//    }
//
//    /**
//     * 发送信息线程
//     */
//    class SendMsg implements Runnable{
//
//        private String msg;
//
//        public SendMsg(String msg) {
//            this.msg = msg;
//        }
//        @Override
//        public void run() {
//            Long userId = getUserIdFromJsonStr(msg);
//            WebSocketServerEndpoint.sendMessage(userId, msg.replace(userId + "-", ""));
//        }
//    }
//}